package com.example.coursemanagement.controller;


import com.example.coursemanagement.MyUtils.CommonResult;
import com.example.coursemanagement.MyUtils.ResultCode;
import com.example.coursemanagement.mapper.ClassMapper;
import com.example.coursemanagement.mapper.CommentMapper;
import com.example.coursemanagement.pojo.Class;
import com.example.coursemanagement.pojo.Comment;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yangmenghen
 * @since 2020-06-01
 */
@RestController
@RequestMapping("/class" )
@RequiredArgsConstructor
public class ClassController{

    private final ClassMapper classMapper;

    @ApiOperation(value = "查看所有班级的信息")
    @RequestMapping(value = "/select",method = RequestMethod.GET)
    public CommonResult<Object> queryClassById(int id){
        Collection<Class> classes = classMapper.selectList(null);
        if(classes==null){
            return CommonResult.failed(ResultCode.FAILED);
        }
        else{
            return CommonResult.success(classes);
        }
    }

    @ApiOperation("新增一个班级")

    @RequestMapping(value = "/addClass",method = RequestMethod.POST)
    public CommonResult<Object> addComment(Class classes){
        if(classMapper.insert(classes)>0){
            return CommonResult.success(ResultCode.ADD_SUCCESS);
        }
        else{
            return CommonResult.failed(ResultCode.FAILED);
        }
    }

    @ApiOperation("删除一个班级")
    @RequestMapping(value = "/deleteClass",method = RequestMethod.DELETE)
    public CommonResult<Object> delete(int id){
        if(classMapper.deleteById(id)>0){
            return CommonResult.success(ResultCode.DELETE_SUCCESS);
        }
        else{
            return CommonResult.failed(ResultCode.FAILED);
        }
    }

}

